package WinterHomework.day10;

//Leetcode27号问题
public class Demo02 {
    public int removeElement(int[] nums, int val) {
        if (nums == null || nums.length == 0) {
            return 0;
        }
        int prev = 0, tail = nums.length - 1;
        while (prev <= tail) {
            if (nums[prev] == val) {
                int temp = nums[prev];
                nums[prev] = nums[tail];
                nums[tail] = temp;
                tail--;
            } else {
                prev++;
            }
        }
        return prev;
    }
}
